package com.nightsoul.cxf;

import org.apache.cxf.interceptor.OutFaultChainInitiatorObserver;
import org.apache.cxf.jaxws.JaxWsClientFactoryBean;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.junit.Test;

import com.nightsoul.cxf.interceptor.in.PreLogicalInterceptor;
import com.nightsoul.cxf.interceptor.out.SendInterceptor;
import com.nightsoul.cxf.interceptor.out.UserLogicalInterceptor;

public class InterceptorExceptionTest {
	public static final String ADDRESS = "http://127.0.0.1:9000/hello";
	
	@Test
	public void testJaxWsServerFactoryBean() throws Exception {
		JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();
		factoryBean.setAddress(ADDRESS);
		factoryBean.setServiceClass(HelloService.class);
		factoryBean.setServiceBean(new HelloServiceImpl());
		factoryBean.getInInterceptors().add(new PreLogicalInterceptor());
		factoryBean.getInInterceptors().add(new MyPreInvokeInterceptor());
		
		factoryBean.getOutInterceptors().add(new UserLogicalInterceptor());
		factoryBean.getOutInterceptors().add(new SendInterceptor());
		factoryBean.create();
	
		OutFaultChainInitiatorObserver ofio;
		
		
		Object object = new Object();
		synchronized (object) {
			object.wait();
		}
	}
	
	@Test
	public void testJaxWsClientFactoryBean() throws Exception {
		JaxWsClientFactoryBean bean = new JaxWsClientFactoryBean();
		bean.setAddress(ADDRESS);
		bean.setServiceClass(HelloService.class);
		bean.create().invoke("sayHello", "xtayfjpk");
	}
	
	public static void main(String[] args) {
		try {
			System.out.println("xxx");
			System.out.println(1/0);
		} catch(RuntimeException e){
			System.out.println("runtime exception");
			throw e;
		} catch (Exception e) {
			System.out.println("exception");
		}
	}
}
